﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Interop;
using Microsoft.Office.Core;
using Common.Protocol;

namespace PPTControl
{
    class PPTUtil
    {
        static public void Open(string path,Application app)
        {
            app.Presentations.Open(path);
        }
          static public string GetNotesText(Slide slide)
          {
              foreach (Microsoft.Office.Interop.PowerPoint.Shape nodeshape in slide.NotesPage.Shapes)
              {
                   
                  if (nodeshape.HasTextFrame.Equals(MsoTriState.msoTrue))
                  {
                     return nodeshape.TextFrame.TextRange.Text;
                  }

              }
              return "";
          }
          static public ControlResp Next(Microsoft.Office.Interop.PowerPoint.Application app)
          {
              int i = app.Presentations.Count;
              ControlResp ret = new ControlResp();
              if (app.SlideShowWindows.Count > 0)
              {
                  app.SlideShowWindows[1].View.Next();
                  ret.Comments = PPTUtil.GetNotesText(app.SlideShowWindows[1].View.Slide);
                  ret.PageNO =app.SlideShowWindows[1].View.Slide.SlideIndex;
              }
              return ret;
          }

          static public ControlResp Previous(Microsoft.Office.Interop.PowerPoint.Application app)
          {
              int i = app.Presentations.Count;
            
              ControlResp ret = new ControlResp();
              ret.PageNO = 0;
              ret.Comments = "";
              if (app.SlideShowWindows.Count > 0)
              {
                  app.SlideShowWindows[1].View.Previous();
                  ret.Comments = PPTUtil.GetNotesText(app.SlideShowWindows[1].View.Slide);
                  ret.PageNO = app.SlideShowWindows[1].View.Slide.SlideIndex;
              }
              return ret;
          }
              
    }
}
